package com.javen.solr;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.solr.client.solrj.SolrQuery.ORDER;
import org.apache.solr.client.solrj.SolrQuery.SortClause;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.zimmur.solr.common.Facet;
import com.zimmur.solr.model.Designer;
import com.zimmur.solr.model.Goods;
import com.zimmur.solr.model.SearchableDesigner;
import com.zimmur.solr.model.SearchableGoods;
import com.zimmur.solr.service.ISolrDesignerService;
import com.zimmur.tools.PageUtil;

@RunWith(SpringJUnit4ClassRunner.class)     //表示继承了SpringJUnit4ClassRunner类  
@ContextConfiguration(locations = {"classpath:spring-mybatis.xml","classpath:spring-solr.xml"})  
public class SolrDesigner {

	@Resource
	private ISolrDesignerService solrDesignerService;
	//@Test
	public void queryAll(){
		int isRescommend=1;
		int displaystatus=1;
		List<Designer> designers=solrDesignerService.queryAll(isRescommend, displaystatus);
		for(Designer d:designers){
			System.out.println(d.toString());
		}
	}
	//@Test
	public void queryWithFacte(){
		int isRecommand=1;
		int displayStatus=1;
		String tags="";
		String key=null;
		int pageNo=1;
		List<SortClause> value=new ArrayList<>();
		value.add(new SortClause(SearchableDesigner.CREATEDATE_FIELD, ORDER.asc));
		Facet facet=new Facet();
		String[] fields={SearchableDesigner.TAGS_FIELD};
		facet.setFields(fields);
		facet.setStatus(true);
		facet.setLimit(5);
		Map<String,Object> map=solrDesignerService.queryWithfacet(isRecommand, displayStatus, tags, key, value, pageNo, facet);
		System.out.println(map.toString());
		//List<FacetField> facetFields= (List<FacetField>)map.get("FacteList");
		//System.out.println(facetFields.toString());
	}
	//@Test
	public void query(){
		int isRecommand=1;
		int displayStatus=1;
		String tags="全部";
		String key="";
		List<SortClause> value=new ArrayList<>();
		value.add(new SortClause(SearchableDesigner.CREATEDATE_FIELD, ORDER.asc));
		int pageNo=1;
		List<Designer> designers=solrDesignerService.query(isRecommand, displayStatus, tags, key, value, pageNo);
		for(Designer d:designers){
			System.out.println(d.toString());
		}
	}
	@Test
	public void queryBytagsAndkey(){
		String tags="";
		String key="";
		int pageNo=1;
		PageUtil<Designer> page=solrDesignerService.queryBytabAndkey(tags, key, pageNo);
		System.out.println(page.getTotalRecord());
		System.out.println(page.getItemList().toString());
	}
}
